def bbox_siou(box1, box2, eps=1e-7):
    # 1 pred 2 gt
    # x1, y1, x2, y2 = box1
    b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, -1)
    b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, -1)
    w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1 + eps
    w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1 + eps

    # Intersection area
    inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
            (torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0)

    # Union Area
    union = w1 * h1 + w2 * h2 - inter + eps

    # IoU
    iou = inter / union

    cw = torch.max(b1_x2, b2_x2) - torch.min(b1_x1, b2_x1)  # convex (smallest enclosing box) width
    ch = torch.max(b1_y2, b2_y2) - torch.min(b1_y1, b2_y1)  # convex height

    c2 = cw ** 2 + ch ** 2 + eps  # convex diagonal squared
    # rho2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4  # center dist ** 2
    cx2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2) / 4
    cy2 = ((b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4
    rho2 = cx2 + cy2
    v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2)
    with torch.no_grad():
        alpha = v / (v - iou + (1 + eps))
    ciou = iou - (rho2 / c2 + v * alpha)  # CIoU

    # siou https://ieeexplore.ieee.org/iel7/6287639/6514899/10477344.pdf
    cta = torch.arcsin(ch / math.sqrt(rho2)) - math.pi / 4
    gama = 2 - math.cos(2 * math.sin(cta))
    lou = (cx2 / (cw ** 2 + eps)) + (cy2 / (ch ** 2 + eps))
    drt = 2 - math.e ** (-gama * lou)
    siou = ciou - drt
    return siou